package Acwing;

import java.util.Scanner;

public class Demo95Other {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int BigV = sc.nextInt();
        int[] value = new int[N + 1];
        int[] weight = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            weight[i] = sc.nextInt();
            value[i] = sc.nextInt();
        }
        int[][] f = new int[N + 1][BigV + 1];
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= BigV; j++) {
                for (int k = 0; k * weight[i] <= j; k++)
                    f[i][j] = Math.max(f[i][j], f[i - 1][j - k * weight[i]] + k * value[i]);
            }

        }
        System.out.println(f[N][BigV]);
    }
}
